<%@ page language="java" contentType="text/html; charset=UTF-8"    pageEncoding="UTF-8"%> 
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html> 
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title></title>
<link href="<%=request.getContextPath() %>/ext/resources/css/ext-all.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="<%=request.getContextPath() %>/ext/ext-all.js"></script>
</head>
<script type="text/javascript">
var shopId= "";
	 <% Object sessionObj = request.getSession().getAttribute("employee") ;
	             	if (sessionObj != null	 ) {
	             		pcjavanet.mobilesell.model.Employee bean = ( pcjavanet.mobilesell.model.Employee )sessionObj;
	            %>
	  shopId='<%=bean.getRefShopId()%>';
	  <%}%>
	Ext.onReady(function(){
		var itemsPerPage = 10;
		var store=new Ext.data.Store({ 
			pageSize: itemsPerPage, 
			fields : [
				'dbid',
				'purchase.name',
				'refPurchaseDbid',
				'refGoodsDbid',
				'goods.name',
				'shop.name',
				'refShopDbid',
				'color.name',
				'refColorDbid',
				'configuration.name',
				'refConfigurationDbid',
				'unit.name',
				'refUnitDbid',
				'intype',
				'price',
				'saleprice',
				'money',
				'number',
				'memo',
				'serialnumber',
				{ name: 'createDate' , type : 'date' },
    		],
    		proxy : {  
   				type : 'ajax', 
				url : '<%=request.getContextPath() %>/storehouse/listStorehouse.action',
   				reader : { type : 'json',root : 'storehousePageBeans' ,totalProperty: 'totalProperty'}   
    		} , 
			autoLoad : false,  
   			timeout: 900000,
		}); 
		var gridPanel= Ext.create('Ext.grid.GridPanel', {
 			store: store,    
			selModel : Ext.create('Ext.selection.CheckboxModel',{   mode: 'SINGLE' }),
			columnLines: true,
			columns: [
					{ text :'dbid', flex : 1 , sortable : true , hidden : true , dataIndex :'dbid' },
					{ text :'Purchase Name ', flex : 1 ,hidden : true , sortable : true , dataIndex :'purchase.name' },
					{ text :'refPurchaseDbid', flex : 1 , sortable : true , hidden : true , dataIndex :'refPurchaseDbid' },
					{ text :'商品名', flex : 1 , sortable : true , dataIndex :'goods.name' },
					{ text :'refGoodsDbid', flex : 1 , sortable : true , hidden : true , dataIndex :'refGoodsDbid' },
					{ text :'仓库名', flex : 1 , sortable : true , dataIndex :'shop.name' },
					{ text :'refShopDbid', flex : 1 , sortable : true , hidden : true , dataIndex :'refShopDbid' },
					{ text :'颜色', flex : 1 , sortable : true , dataIndex :'color.name' },
					{ text :'refColorDbid', flex : 1 , sortable : true , hidden : true , dataIndex :'refColorDbid' },
					{ text :'配置', flex : 1 , sortable : true , dataIndex :'configuration.name' },
					{ text :'refConfigurationDbid', flex : 1 , sortable : true , hidden : true , dataIndex :'refConfigurationDbid' },
					{ text :'单位', flex : 1 , sortable : true , dataIndex :'unit.name' },
					{ text :'refUnitDbid', flex : 1 , sortable : true , hidden : true , dataIndex :'refUnitDbid' },
					{ text :'intype', flex : 1 , sortable : true ,hidden:true, dataIndex :'intype' },
					{ text : '进货价格', flex : 1 , sortable : true , dataIndex :'price' },
					{ text :'销售价格', flex : 1 , sortable : true , dataIndex :'saleprice' },
					{ text :'money', flex : 1 , sortable : true , dataIndex :'money' },
					{ text :'number', flex : 1 , sortable : true , hidden : true ,dataIndex :'number' },
					{ text :'备注', flex : 1 , sortable : true , dataIndex :'memo' },
					{ text :'串号', flex : 1 , sortable : true , dataIndex :'serialnumber' },
					{ text :'createDate', flex : 1 , sortable : true , dataIndex :'createDate',hidden : true , renderer:Ext.util.Format.dateRenderer('Y-m-d'), },
			],
			height: 350,
			width: 600,
			tbar: new Ext.Toolbar({
				height : '32' , autoWidth:true, autoShow:true,
				items:[
				{ xtype: 'button', text: '新增',tooltip: 'Add New Row',
					handler:  function (){
						var popWindow = new Ext.Window({
							id : 'AddStorehouseWindow',
				    		width : 600,
				    		title : '新增一条记录.', 
				    		closable: true, 
				    		resizable: true,
				    		constrainHeader: true,
				    		modal: true,
				    	    plain: true, 
				    		layout : 'fit',
				    		x : 250, y : 100,
				    		items :[{
				    			xtype: 'form',
				    			id : 'addForm',
				    			layout: 'form',
				    			frame: true,
				    			bodyPadding: '2 2 0',
				    			fieldDefaults: {
				    				msgTarget: 'side',
				    				labelWidth: 75
				    			},
				    			defaultType: 'textfield',
				    			items :[
								{ 
									xtype: 'combo',
									store: { xtype :'Ext.data.Store', fields:['dbid','name'],proxy :{ type:'ajax',url:'<%=request.getContextPath() %>/goods/listGoods.action', reader : { type : 'json' , root : 'goodsPageBeans'} } ,autoLoad: true },
									valueField:'dbid', 
									displayField:'name', 
									blankText:'请选择', 
									editable : true , 
									emptyText:'请选择', 
									forceSelection: true, 
									fieldLabel: '商品',
									name: 'refGoodsDbid',
									id: 'refGoodsDbid',
									listeners : { 'select' :      function(combop, record, index) {
											Ext.Ajax.request({
							 	   				url : '<%=request.getContextPath() %>/goods/queryGoods.action',
							 	   				method : 'post',
							 	   				params : { dbid: this.getValue() },
							 	   				success : function(response, options) {
							 	   					var data2 =eval("("+response.responseText+")");
							 	   					Ext.getCmp("addForm").getForm().findField("refConfigurationDbid").setValue( data2.bean.refConfigurationDbid );
							 	   					Ext.getCmp("addForm").getForm().findField("refUnitDbid").setValue(  data2.bean.refUnitDbid  );
							 	   					Ext.getCmp("addForm").getForm().findField("refUnitDbid").setValue(  data2.bean.refUnitDbid  );
							 	   				}
							 	   			}
							 	   		);
										}  
									}
								}, 
// 				    			 { 
// 				    					xtype: 'combo',
//			    					    store: { xtype :'Ext.data.Store', fields:['dbid','name'],proxy :{ type:'ajax',url:'<%=request.getContextPath() %>/purchase/listPurchase.action', reader : { type : 'json' , root : 'purchasePageBeans'} } ,autoLoad: true },
// 				    					valueField:'dbid', 
// 				    	catatypeid				displayField:'name', 
				    				//	 blankText:'Please Select', 
				    				//	  editable : true , 
				    				//	 emptyText:'please Select', 
				    				//	 forceSelection: true, 
// 				    					fieldLabel: 'Purchase',
// 				    					name: 'refPurchaseDbid',
// 				    					id: 'refPurchaseDbid',
// 				    			 }, 
				    			 { 
				    					xtype: 'combo',
				    					store: { xtype :'Ext.data.Store', fields:['dbid','name'],proxy :{ type:'ajax',url:'<%=request.getContextPath() %>/shop/listShop.action', reader : { type : 'json' , root : 'shopPageBeans'} } ,autoLoad: true },
				    					valueField:'dbid', 
				    					displayField:'name', 
				    				//	 blankText:'Please Select', 
				    				//	  editable : true , 
				    				//	 emptyText:'please Select', 
				    				//	 forceSelection: true, 
				    					fieldLabel: '仓库',
				    					name: 'refShopDbid',
				    					id: 'refShopDbid',
				    			 }, 
				    			 { 
				    					xtype: 'combo',
				    					store: { xtype :'Ext.data.Store', fields:['dbid','name'],proxy :{ type:'ajax',url:'<%=request.getContextPath() %>/color/listColor.action', reader : { type : 'json' , root : 'colorPageBeans'} } ,autoLoad: true },
				    					valueField:'dbid', 
				    					displayField:'name', 
				    				//	 blankText:'Please Select', 
				    				//	  editable : true , 
				    				//	 emptyText:'please Select', 
				    				//	 forceSelection: true, 
				    					fieldLabel: '颜色',
				    					name: 'refColorDbid',
				    					id: 'refColorDbid',
				    			 }, 
				    			 { 
				    					xtype: 'combo',
				    					store: { xtype :'Ext.data.Store', fields:['dbid','name'],proxy :{ type:'ajax',url:'<%=request.getContextPath() %>/configuration/listConfiguration.action', reader : { type : 'json' , root : 'configurationPageBeans'} } ,autoLoad: true },
				    					valueField:'dbid', 
				    					displayField:'name', 
				    				//	 blankText:'Please Select', 
				    				//	  editable : true , 
				    				//	 emptyText:'please Select', 
				    				//	 forceSelection: true, 
				    					fieldLabel: '配置',
				    					name: 'refConfigurationDbid',
				    					id: 'refConfigurationDbid',
				    			 }, 
				    			 { 
				    					xtype: 'combo',
				    					store: { xtype :'Ext.data.Store', fields:['dbid','name'],proxy :{ type:'ajax',url:'<%=request.getContextPath() %>/unit/listUnit.action', reader : { type : 'json' , root : 'unitPageBeans'} } ,autoLoad: true },
				    					valueField:'dbid', 
				    					displayField:'name', 
				    				//	 blankText:'Please Select', 
				    				//	  editable : true , 
				    				//	 emptyText:'please Select', 
				    				//	 forceSelection: true, 
				    					fieldLabel: '单位',
				    					name: 'refUnitDbid',
				    					id: 'refUnitDbid',
				    			 }, 
				    			 { 
				    					xtype: 'numberfield',
				    					fieldLabel: 'intype',
				    					name: 'intype',
				    					id: 'intype',
				    					hidden :true
				    			 }, 
				    			 { 
				    					xtype: 'numberfield',
				    					fieldLabel: '进货价',
				    					name: 'price',
				    					id: 'price',
				    			 }, 
				    			 { 
				    					xtype: 'numberfield',
				    					fieldLabel: '销售价',
				    					name: 'saleprice',
				    					id: 'saleprice',
				    			 }, 
				    			 { 
				    					xtype: 'numberfield',
				    					fieldLabel: '价钱',
				    					name: 'money',
				    					id: 'money',
				    			 }, 
				    			 { 
				    					xtype: 'textfield',
				    					fieldLabel: '串号',
				    					name: 'serialnumber',
				    					id: 'serialnumber',
				    			 }, 
				    			 { 
				    					xtype: 'numberfield',
				    					fieldLabel: '数量',
				    					name: 'number',
				    					id: 'number',
				    			 }, 
				    			 { 
				    					xtype: 'textfield',
				    					fieldLabel: '备注',
				    					name: 'memo',
				    					id: 'memo',
				    			 }, 
				    			 { 
				    					xtype: 'textfield',
				    					fieldLabel: '串号',
				    					name: 'serialnumber',
				    					id: 'serialnumber',
				    			 }, 
				    			 { 
				    					xtype: 'datefield',
				    					format: 'Y-m-d H:i:s',
				    					fieldLabel: 'createDate',
				    					name: 'createDate',
				    					id: 'createDate',
				    					value : new Date(),
				    					hidden : true
				    			 }, 
				    			],
				    			 buttons :[
				    			 { 
				    					xtype: 'button',
				    					text: '保存',
				    					name: 'SaveAddBtn',
				    					id: 'SaveAddBtn',
				    					handler:  function (){ 
				    						     this.up('form').getForm().doAction('submit',{ 
				    					             url:'<%=request.getContextPath() %>/storehouse/insertStorehouse.action', 
				    					             method:'post', 
				    					             params:'', 
				    					             success:function(form,action){ 
				    					                 Ext.Msg.alert('新增成功',action.result.info); 
				    					                 popWindow.close(); 
				    					                 store.reload(); 
				    					             }, 
				    					             failure:function(e){ 
				    					           	  console.info( e); 
				    					                  Ext.Msg.alert('error','Fail'); 
				    					             } 
				    					           }); 
				    					},
				    			 }, 
				    			 { 
				    					xtype: 'button',
				    					text: '重置',
				    					name: 'ResetAddBtn',
				    					id: 'ResetAddBtn',
				    					handler:  function (){  this.up('form').getForm().reset();},
				    			 }, 
				    			 { 
				    					xtype: 'button',
				    					text: 'Close',
				    					name: 'CloseAddBtn',
				    					id: 'CloseAddBtn',
				    					handler:  function (){  popWindow.close();},
				    			 }, 
				    			 ] 
				    		}]
				    	});
						popWindow.show();
					}
				} ,
				{ xtype: 'button', text: '更新',tooltip: 'Update Row',
					handler:  function (param){
						var grid = this.ownerCt.ownerCt; 
						var checkRecord = grid.getSelectionModel().getSelection(); 
						if (checkRecord.length != 0) {
							var popWindow = new Ext.Window({
								id : 'updateWindow',
				    			width : 600,
				    			title : '更新记录.', 
				    			closable: true, 
				    			resizable: true,
				    			constrainHeader: true,
				    			modal: true,
				    	   		plain: true, 
				    			layout : 'fit',
				    			x : 250, y : 100,
				    			items :[{
				    				xtype: 'form',
				    				id: 'updateForm',
				    				layout: 'form',
				    				frame: true,
				    				bodyPadding: '2 2 0',
				    				fieldDefaults: {
				    					msgTarget: 'side',
				    					labelWidth: 75
				    				},
				    				defaultType: 'textfield',
				    				items :[
				    			 	{ 
				    					xtype: 'numberfield',
				    					fieldLabel: '编号', hidden :true ,
				    					name: 'dbid',
				    					id: 'dbid',
				    					readOnly: true,
				    			 }, 
				    			 { 
				    					xtype: 'combo',
				    					store: { xtype :'Ext.data.Store', fields:['dbid','name'],proxy :{ type:'ajax',url:'<%=request.getContextPath() %>/purchase/listPurchase.action', reader : { type : 'json' , root : 'purchasePageBeans'} } ,autoLoad: true },
				    					valueField:'dbid', 
				    					displayField:'name', 
				    				//	 blankText:'Please Select', 
				    				//	  editable : false, , 
				    				//	 emptyText:'please Select', 
				    				//	 forceSelection: true, 
				    					fieldLabel: 'Purchase',
				    					name: 'refPurchaseDbid',
				    					id: 'refPurchaseDbid',
				    					hidden : true
				    			 }, 
				    			 { 
										xtype: 'combo',
										store: { xtype :'Ext.data.Store', fields:['dbid','name'],proxy :{ type:'ajax',url:'<%=request.getContextPath() %>/goods/listGoods.action', reader : { type : 'json' , root : 'goodsPageBeans'} } ,autoLoad: true },
										valueField:'dbid', 
										displayField:'name', 
										blankText:'请选择', 
										editable : true , 
										emptyText:'请选择', 
// 										forceSelection: true, 
										fieldLabel: '商品',
										name: 'refGoodsDbid',
										id: 'refGoodsDbid',
										listeners : { 'select' :      function(combop, record, index) {
												Ext.Ajax.request({
								 	   				url : '<%=request.getContextPath() %>/goods/queryGoods.action',
								 	   				method : 'post',
								 	   				params : { dbid: this.getValue() },
								 	   				success : function(response, options) {
								 	   					var data2 =eval("("+response.responseText+")");
								 	   					console.info( data2.bean );
								 	   					Ext.getCmp("addForm").getForm().findField("refConfigurationDbid").setValue( data2.bean.refConfigurationDbid );
								 	   					Ext.getCmp("addForm").getForm().findField("refUnitDbid").setValue(  data2.bean.refUnitDbid  );
								 	   					Ext.getCmp("addForm").getForm().findField("refUnitDbid").setValue(  data2.bean.refUnitDbid  );
								 	   				}
								 	   			}
								 	   		);
											}  
										}
									}, 
				    			 { 
				    					xtype: 'combo',
				    					store: { xtype :'Ext.data.Store', fields:['dbid','name'],proxy :{ type:'ajax',url:'<%=request.getContextPath() %>/shop/listShop.action', reader : { type : 'json' , root : 'shopPageBeans'} } ,autoLoad: true },
				    					valueField:'dbid', 
				    					displayField:'name', 
				    				//	 blankText:'Please Select', 
				    				//	  editable : false, , 
				    				//	 emptyText:'please Select', 
				    				//	 forceSelection: true, 
				    					fieldLabel: '仓库',
				    					name: 'refShopDbid',
				    					id: 'refShopDbid',
				    			 }, 
				    			 { 
				    					xtype: 'combo',
				    					store: { xtype :'Ext.data.Store', fields:['dbid','name'],proxy :{ type:'ajax',url:'<%=request.getContextPath() %>/color/listColor.action', reader : { type : 'json' , root : 'colorPageBeans'} } ,autoLoad: true },
				    					valueField:'dbid', 
				    					displayField:'name', 
				    				//	 blankText:'Please Select', 
				    				//	  editable : false, , 
				    				//	 emptyText:'please Select', 
				    				//	 forceSelection: true, 
				    					fieldLabel: 'Color',
				    					name: 'refColorDbid',
				    					id: 'refColorDbid',
				    			 }, 
				    			 { 
				    					xtype: 'combo',
				    					store: { xtype :'Ext.data.Store', fields:['dbid','name'],proxy :{ type:'ajax',url:'<%=request.getContextPath() %>/configuration/listConfiguration.action', reader : { type : 'json' , root : 'configurationPageBeans'} } ,autoLoad: true },
				    					valueField:'dbid', 
				    					displayField:'name', 
				    				//	 blankText:'Please Select', 
				    				//	  editable : false, , 
				    				//	 emptyText:'please Select', 
				    				//	 forceSelection: true, 
				    					fieldLabel: '配置',
				    					name: 'refConfigurationDbid',
				    					id: 'refConfigurationDbid',
				    			 }, 
				    			 { 
				    					xtype: 'combo',
				    					store: { xtype :'Ext.data.Store', fields:['dbid','name'],proxy :{ type:'ajax',url:'<%=request.getContextPath() %>/unit/listUnit.action', reader : { type : 'json' , root : 'unitPageBeans'} } ,autoLoad: true },
				    					valueField:'dbid', 
				    					displayField:'name', 
				    				//	 blankText:'Please Select', 
				    				//	  editable : false, , 
				    				//	 emptyText:'please Select', 
				    				//	 forceSelection: true, 
				    					fieldLabel: '单位',
				    					name: 'refUnitDbid',
				    					id: 'refUnitDbid',
				    			 }, 
				    			 { 
				    					xtype: 'numberfield',
				    					fieldLabel: 'intype',
				    					name: 'intype',
				    					id: 'intype',
				    					hidden : true
				    			 }, 
				    			 { 
				    					xtype: 'numberfield',
				    					fieldLabel: '价格',
				    					name: 'price',
				    					id: 'price',
				    			 }, 
				    			 { 
				    					xtype: 'numberfield',
				    					fieldLabel: '最低销售价格',
				    					name: 'saleprice',
				    					id: 'saleprice',
				    			 }, 
				    			 { 
				    					xtype: 'numberfield',
				    					fieldLabel: '价钱',
				    					name: 'money',
				    					id: 'money',
				    			 }, 
				    			 { 
				    					xtype: 'numberfield',
				    					fieldLabel: '数量',
				    					name: 'number',
				    					id: 'number',
				    			 }, 
				    			 { 
				    					xtype: 'textfield',
				    					fieldLabel: '备注',
				    					name: 'memo',
				    					id: 'memo',
				    			 }, 
				    			 { 
				    					xtype: 'textfield',
				    					fieldLabel: '串号',
				    					name: 'serialnumber',
				    					id: 'serialnumber',
				    			 }, 
				    			 { 
				    					xtype: 'datefield',
				    					format: 'Y-m-d H:i:s',
				    					fieldLabel: '产生日期',
				    					name: 'createDate',
				    					id: 'createDate',
				    					hidden : true 
				    			 }, 
				    			],
				    			 buttons :[
				    			 { 
				    					xtype: 'button',
				    					text: '保存更新',
				    					name: 'SaveUppdateBtn',
				    					id: 'SaveUppdateBtn',
				    					handler:  function (){ 
				    						     this.up('form').getForm().doAction('submit',{ 
				    					             url:'<%=request.getContextPath() %>/storehouse/updateStorehouse.action', 
				    					             method:'post', 
				    					             params:'', 
				    					             success:function(form,action){ 
				    					                 Ext.Msg.alert('更新成功',action.result.info); 
				    					                 popWindow.close(); 
				    					                 store.reload(); 
				    					             }, 
				    					             failure:function(e){ 
				    					           	  console.info( e); 
				    					                  Ext.Msg.alert('error','Fail'); 
				    					             } 
				    					           }); 
				    					},
				    			 }, 
				    			 { 
				    					xtype: 'button',
				    					text: '重置',
				    					name: 'ResetUpdateBtn',
				    					id: 'ResetUpdateBtn',
				    					handler:  function (){  this.up('form').getForm().reset();},
				    			 }, 
				    			 { 
				    					xtype: 'button',
				    					text: '关闭',
				    					name: 'CloseAddBtn',
				    					id: 'CloseAddBtn',
				    					handler:  function (){  popWindow.close();},
				    			 }, 
				    			 ] 
				    			}]
				    		});
							popWindow.show();
							Ext.getCmp("updateForm").getForm().loadRecord(checkRecord[0]);
							Ext.getCmp("updateForm").getForm().findField("refPurchaseDbid").setValue( checkRecord[0].data["refPurchaseDbid"]);
							Ext.getCmp("updateForm").getForm().findField("refShopDbid").setValue( checkRecord[0].data["refShopDbid"]);
							Ext.getCmp("updateForm").getForm().findField("refColorDbid").setValue( checkRecord[0].data["refColorDbid"]);
							Ext.getCmp("updateForm").getForm().findField("refGoodsDbid").setValue( checkRecord[0].data["refGoodsDbid"]);
							Ext.getCmp("updateForm").getForm().findField("refConfigurationDbid").setValue( checkRecord[0].data["refConfigurationDbid"]);
							Ext.getCmp("updateForm").getForm().findField("refUnitDbid").setValue( checkRecord[0].data["refUnitDbid"]);
						}else{
							Ext.MessageBox.alert('错误提示','请至少选择一条信?');
				      }
				    }
				} , 
				{ xtype: 'button', text: '删除',tooltip: 'Delete Row',
					handler:  function (){
						var grid = this.ownerCt.ownerCt;
					 Ext.MessageBox.confirm('Confirm', '确定要删除该记录吗?',
							 function showResult(btn,text){
							 	if (btn == "yes"){
									var store = grid.getStore();
									var checkRecord = grid.getSelectionModel().getSelection();
									if (checkRecord.length != 0) {
										Ext.Ajax.request({
											url : '<%=request.getContextPath() %>/storehouse/deleteStorehouse.action',
											params : { dbid : checkRecord[0].data["dbid"] },
											success : function(response, options) {},
										});
										store.remove(checkRecord);
									}else{
										Ext.MessageBox.alert('信息提示','请选择一条记录!');
				       				}
								}
							}
						);
					}
				}
				 , 
				{ xtype: 'button', text: '复制',tooltip: 'Delete Row',
					handler:  function (){

						var grid = this.ownerCt.ownerCt; 
						var checkRecord = grid.getSelectionModel().getSelection(); 
						if (checkRecord.length != 0) {
							var popWindow = new Ext.Window({
								id : 'updateWindow',
				    			width : 600,
				    			title : '更新记录.', 
				    			closable: true, 
				    			resizable: true,
				    			constrainHeader: true,
				    			modal: true,
				    	   		plain: true, 
				    			layout : 'fit',
				    			x : 250, y : 100,
				    			items :[{
				    				xtype: 'form',
				    				id: 'updateForm',
				    				layout: 'form',
				    				frame: true,
				    				bodyPadding: '2 2 0',
				    				fieldDefaults: {
				    					msgTarget: 'side',
				    					labelWidth: 75
				    				},
				    				defaultType: 'textfield',
				    			items :[
				    			 { 
				    					xtype: 'numberfield',
				    					fieldLabel: '编号', hidden :true ,
				    					name: 'dbid',
				    					id: 'dbid',
				    					readOnly: true,
				    			 }, 
				    			 { 
				    					xtype: 'combo',
				    					store: { xtype :'Ext.data.Store', fields:['dbid','name'],proxy :{ type:'ajax',url:'<%=request.getContextPath() %>/purchase/listPurchase.action', reader : { type : 'json' , root : 'purchasePageBeans'} } ,autoLoad: true },
				    					valueField:'dbid', 
				    					displayField:'name', 
				    				//	 blankText:'Please Select', 
				    				//	  editable : false, , 
				    				//	 emptyText:'please Select', 
				    				//	 forceSelection: true, 
				    					fieldLabel: 'Purchase',
				    					name: 'refPurchaseDbid',
				    					id: 'refPurchaseDbid',
				    					hidden : true
				    			 }, 
				    			 { 
										xtype: 'combo',
										store: { xtype :'Ext.data.Store', fields:['dbid','name'],proxy :{ type:'ajax',url:'<%=request.getContextPath() %>/goods/listGoods.action', reader : { type : 'json' , root : 'goodsPageBeans'} } ,autoLoad: true },
										valueField:'dbid', 
										displayField:'name', 
										blankText:'请选择', 
										editable : true , 
										emptyText:'请选择', 
// 										forceSelection: true, 
										fieldLabel: '商品',
										name: 'refGoodsDbid',
										id: 'refGoodsDbid',
										listeners : { 'select' :      function(combop, record, index) {
												Ext.Ajax.request({
								 	   				url : '<%=request.getContextPath() %>/goods/queryGoods.action',
								 	   				method : 'post',
								 	   				params : { dbid: this.getValue() },
								 	   				success : function(response, options) {
								 	   					var data2 =eval("("+response.responseText+")");
								 	   					console.info( data2.bean );
								 	   					Ext.getCmp("addForm").getForm().findField("refConfigurationDbid").setValue( data2.bean.refConfigurationDbid );
								 	   					Ext.getCmp("addForm").getForm().findField("refUnitDbid").setValue(  data2.bean.refUnitDbid  );
								 	   					Ext.getCmp("addForm").getForm().findField("refUnitDbid").setValue(  data2.bean.refUnitDbid  );
								 	   				}
								 	   			}
								 	   		);
											}  
										}
									}, 
				    			 { 
				    					xtype: 'combo',
				    					store: { xtype :'Ext.data.Store', fields:['dbid','name'],proxy :{ type:'ajax',url:'<%=request.getContextPath() %>/shop/listShop.action', reader : { type : 'json' , root : 'shopPageBeans'} } ,autoLoad: true },
				    					valueField:'dbid', 
				    					displayField:'name', 
				    				//	 blankText:'Please Select', 
				    				//	  editable : false, , 
				    				//	 emptyText:'please Select', 
				    				//	 forceSelection: true, 
				    					fieldLabel: '仓库',
				    					name: 'refShopDbid',
				    					id: 'refShopDbid',
				    			 }, 
				    			 { 
				    					xtype: 'combo',
				    					store: { xtype :'Ext.data.Store', fields:['dbid','name'],proxy :{ type:'ajax',url:'<%=request.getContextPath() %>/color/listColor.action', reader : { type : 'json' , root : 'colorPageBeans'} } ,autoLoad: true },
				    					valueField:'dbid', 
				    					displayField:'name', 
				    				//	 blankText:'Please Select', 
				    				//	  editable : false, , 
				    				//	 emptyText:'please Select', 
				    				//	 forceSelection: true, 
				    					fieldLabel: '颜色',
				    					name: 'refColorDbid',
				    					id: 'refColorDbid',
				    			 }, 
				    			 { 
				    					xtype: 'combo',
				    					store: { xtype :'Ext.data.Store', fields:['dbid','name'],proxy :{ type:'ajax',url:'<%=request.getContextPath() %>/configuration/listConfiguration.action', reader : { type : 'json' , root : 'configurationPageBeans'} } ,autoLoad: true },
				    					valueField:'dbid', 
				    					displayField:'name', 
				    				//	 blankText:'Please Select', 
				    				//	  editable : false, , 
				    				//	 emptyText:'please Select', 
				    				//	 forceSelection: true, 
				    					fieldLabel: '配置',
				    					name: 'refConfigurationDbid',
				    					id: 'refConfigurationDbid',
				    			 }, 
				    			 { 
				    					xtype: 'combo',
				    					store: { xtype :'Ext.data.Store', fields:['dbid','name'],proxy :{ type:'ajax',url:'<%=request.getContextPath() %>/unit/listUnit.action', reader : { type : 'json' , root : 'unitPageBeans'} } ,autoLoad: true },
				    					valueField:'dbid', 
				    					displayField:'name', 
				    				//	 blankText:'Please Select', 
				    				//	  editable : false, , 
				    				//	 emptyText:'please Select', 
				    				//	 forceSelection: true, 
				    					fieldLabel: '单位',
				    					name: 'refUnitDbid',
				    					id: 'refUnitDbid',
				    			 }, 
				    			 { 
				    					xtype: 'numberfield',
				    					fieldLabel: 'intype',
				    					name: 'intype',
				    					id: 'intype',
				    					hidden : true
				    			 }, 
				    			 { 
				    					xtype: 'numberfield',
				    					fieldLabel: '价格',
				    					name: 'price',
				    					id: 'price',
				    			 }, 
				    			 { 
				    					xtype: 'numberfield',
				    					fieldLabel: '最低销售价格',
				    					name: 'saleprice',
				    					id: 'saleprice',
				    			 }, 
				    			 { 
				    					xtype: 'numberfield',
				    					fieldLabel: '价钱',
				    					name: 'money',
				    					id: 'money',
				    			 }, 
				    			 { 
				    					xtype: 'numberfield',
				    					fieldLabel: '数量',
				    					name: 'number',
				    					id: 'number',
				    			 }, 
				    			 { 
				    					xtype: 'textfield',
				    					fieldLabel: '备注',
				    					name: 'memo',
				    					id: 'memo',
				    			 }, 
				    			 { 
				    					xtype: 'textfield',
				    					fieldLabel: '串号',
				    					name: 'serialnumber',
				    					id: 'serialnumber',
				    			 }, 
				    			 { 
				    					xtype: 'datefield',
				    					format: 'Y-m-d H:i:s',
				    					fieldLabel: '产生日期',
				    					name: 'createDate',
				    					id: 'createDate',
				    					hidden : true 
				    			 }, 
				    			],
				    			 buttons :[
				    			 { 
				    					xtype: 'button',
				    					text: '保存复制',
				    					name: 'SaveUppdateBtn',
				    					id: 'SaveUppdateBtn',
				    					handler:  function (){ 
				    						     this.up('form').getForm().doAction('submit',{ 
				    					             url:'<%=request.getContextPath() %>/storehouse/insertStorehouse.action', 
				    					             method:'post', 
				    					             params:'', 
				    					             success:function(form,action){ 
				    					                 Ext.Msg.alert('复制成功',action.result.info); 
				    					                 popWindow.close(); 
				    					                 store.reload(); 
				    					             }, 
				    					             failure:function(e){ 
				    					           	  console.info( e); 
				    					                  Ext.Msg.alert('error','Fail'); 
				    					             } 
				    					           }); 
				    					},
				    			 }, 
				    			 { 
				    					xtype: 'button',
				    					text: '重置',
				    					name: 'ResetUpdateBtn',
				    					id: 'ResetUpdateBtn',
				    					handler:  function (){  this.up('form').getForm().reset();},
				    			 }, 
				    			 { 
				    					xtype: 'button',
				    					text: '关闭',
				    					name: 'CloseAddBtn',
				    					id: 'CloseAddBtn',
				    					handler:  function (){  popWindow.close();},
				    			 }, 
				    			 ] 
				    			}]
				    		});
							popWindow.show();
							Ext.getCmp("updateForm").getForm().loadRecord(checkRecord[0]);
							Ext.getCmp("updateForm").getForm().findField("refPurchaseDbid").setValue( checkRecord[0].data["refPurchaseDbid"]);
							Ext.getCmp("updateForm").getForm().findField("refShopDbid").setValue( checkRecord[0].data["refShopDbid"]);
							Ext.getCmp("updateForm").getForm().findField("refColorDbid").setValue( checkRecord[0].data["refColorDbid"]);
							Ext.getCmp("updateForm").getForm().findField("refGoodsDbid").setValue( checkRecord[0].data["refGoodsDbid"]);
							Ext.getCmp("updateForm").getForm().findField("refConfigurationDbid").setValue( checkRecord[0].data["refConfigurationDbid"]);
							Ext.getCmp("updateForm").getForm().findField("refUnitDbid").setValue( checkRecord[0].data["refUnitDbid"]);
						}else{
							Ext.MessageBox.alert('错误提示','请至少选择一条信?');
				      }
					}
				}
			] 
		}) ,
		viewConfig : { forceFit : true, scrollOffset : 0 },
		dockedItems: [{ xtype: 'pagingtoolbar', store: store,  dock: 'bottom', displayInfo: true  }],
		title: '商品列表',
		}); 
		var searchPanel = Ext.create('Ext.form.Panel', {
		    defaultType: 'textfield',
			layout: { type: 'column', align: 'stretch',padding: 5 },
			frame: true,
		    items: [{
		    	columnWidth:0.5,
				xtype: 'container',
				flex: 1,
				border:false, 
				layout: 'anchor',
				defaultType: 'textfield',
				items: [
				        {
							xtype: 'combo',
							store: { xtype :'Ext.data.Store', fields:['dbid','name'],proxy :{ type:'ajax',url:'<%=request.getContextPath() %>/purchase/listPurchase.action', reader : { type : 'json' , root : 'purchasePageBeans'} } ,autoLoad: true },
							valueField:'dbid', 
							displayField:'name', 
							fieldLabel: 'Purchase',
		   					anchor:'95%',
		   					name: 'qryBeginIntRefPurchaseDbid',
		   					id: 'qryBeginIntRefPurchaseDbid',
				        },
				        {
							xtype: 'combo',
							store: { xtype :'Ext.data.Store', fields:['dbid','name'],proxy :{ type:'ajax',url:'<%=request.getContextPath() %>/color/listColor.action', reader : { type : 'json' , root : 'colorPageBeans'} } ,autoLoad: true },
							valueField:'dbid', 
							displayField:'name', 
							fieldLabel: '颜色',
		   					anchor:'95%',
		   					name: 'qryBeginIntRefColorDbid',
		   					id: 'qryBeginIntRefColorDbid',
				        },
				        {
							xtype: 'combo',
							store: { xtype :'Ext.data.Store', fields:['dbid','name'],proxy :{ type:'ajax',url:'<%=request.getContextPath() %>/unit/listUnit.action', reader : { type : 'json' , root : 'unitPageBeans'} } ,autoLoad: true },
							valueField:'dbid', 
							displayField:'name', 
							fieldLabel: '单位',
		   					anchor:'95%',
		   					name: 'qryBeginIntRefUnitDbid',
		   					id: 'qryBeginIntRefUnitDbid',
				        },
				        {
							xtype : 'numberfield',
		   					fieldLabel: '数量',
		   					anchor:'95%',
		   					name: 'qryBeginIntNumber',
		   					id: 'qryBeginIntNumber',
				        },
// 				        {
// 							xtype : 'datefield',
// 							format: 'Y-m-d',
// 		   					fieldLabel: 'CreateDate End',
// 		   					name: 'qryEndDateCreateDate',
// 		   					id: 'qryEndDateCreateDate',
// 		   					anchor:'95%'
// 				        },
				]
			},{
				columnWidth:0.5,
				xtype: 'container',
				flex: 1,
				layout: 'anchor', 
				defaultType: 'textfield',
				items: [
				        {
							xtype: 'combo',
							store: { xtype :'Ext.data.Store', fields:['dbid','name'],proxy :{ type:'ajax',url:'<%=request.getContextPath() %>/shop/listShop.action', reader : { type : 'json' , root : 'shopPageBeans'} } ,autoLoad: true },
							valueField:'dbid', 
							displayField:'name', 
							fieldLabel: '店铺',
		   					anchor:'95%',
		   					name: 'qryBeginIntRefShopDbid',
		   					id: 'qryBeginIntRefShopDbid',
				        },
				        {
							xtype: 'combo',
							store: { xtype :'Ext.data.Store', fields:['dbid','name'],proxy :{ type:'ajax',url:'<%=request.getContextPath() %>/configuration/listConfiguration.action', reader : { type : 'json' , root : 'configurationPageBeans'} } ,autoLoad: true },
							valueField:'dbid', 
							displayField:'name', 
							fieldLabel: '配置',
		   					anchor:'95%',
		   					name: 'qryBeginIntRefConfigurationDbid',
		   					id: 'qryBeginIntRefConfigurationDbid',
				        },
				        {
							xtype : 'numberfield',
		   					fieldLabel: 'Intype',
		   					anchor:'95%',
		   					name: 'qryBeginIntIntype',
		   					id: 'qryBeginIntIntype',
				        },
				        {
							xtype : 'textfield',
		   					fieldLabel: '备注',
		   					name: 'qryBeginStringMemo',
		   					id: 'qryBeginStringMemo',
		   					anchor:'95%'
				        },
				        {
							xtype : 'textfield',
		   					fieldLabel: '串号',
		   					name: 'qryBeginStringSerailnumber',
		   					id: 'qryBeginStringSerailnumber',
		   					anchor:'95%'
				        },
// 				        {
// 							xtype : 'datefield',
// 							format: 'Y-m-d',
// 		   					fieldLabel: 'CreateDate From',
// 		   					name: 'qryBeginDateCreateDate',
// 		   					id: 'qryBeginDateCreateDate',
// 		   					anchor:'95%'
// 				        },
		{
	xtype :'checkbox',
	fieldLabel: '模糊查询',
	name: 'qryLikeEnable',
	id : 'qryLikeEnable',
	anchor:'95%'
}
				]
			}]
			,
			buttons: [{
		        text: '查找',
		        handler: function() {
		            store.load();
		        }
		    },{
		        text: '重置',
		        handler: function() {
		            this.up('form').getForm().reset();
		        }
		    }]
		 });
		store.load({
			params : {
				//username : username,
				start:0 ,
				limit: itemsPerPage 
 			}
		});
 		store.on('beforeload',function(){
	 		Ext.apply(  store.proxy.extraParams, {
				qryLikeEnable : Ext.getCmp("qryLikeEnable").getValue(),
				qryBeginIntRefPurchaseDbid : Ext.getCmp("qryBeginIntRefPurchaseDbid").getValue(),
				qryBeginIntRefShopDbid : Ext.getCmp("qryBeginIntRefShopDbid").getValue(),
				qryBeginIntRefColorDbid : Ext.getCmp("qryBeginIntRefColorDbid").getValue(),
				qryBeginIntRefConfigurationDbid : Ext.getCmp("qryBeginIntRefConfigurationDbid").getValue(),
				qryBeginIntRefUnitDbid : Ext.getCmp("qryBeginIntRefUnitDbid").getValue(),
				qryBeginIntIntype : Ext.getCmp("qryBeginIntIntype").getValue(),
				qryBeginIntNumber : Ext.getCmp("qryBeginIntNumber").getValue(),
				qryBeginStringMemo : Ext.getCmp("qryBeginStringMemo").getValue(),
// 				qryBeginDateCreateDate : Ext.getCmp("qryBeginDateCreateDate").getRawValue(),
// 				qryEndDateCreateDate : Ext.getCmp("qryEndDateCreateDate").getRawValue(),
			})
		});
		var mainPanel =Ext.create('Ext.panel.Panel', {
			id : 'storehouseMainPanel',
			layout: { type: 'vbox', align: 'stretch',padding: 5 },
			items: [ searchPanel , gridPanel  ],
			renderTo: Ext.getBody(),
		})
	});
</script>
